const gulp = require("gulp")
const ts = require("gulp-typescript")
const gulpTslint = require("gulp-tslint")
const tsLint = require('tslint')

const tsProject = ts.createProject("tsconfig.json")

gulp.task('ts', function () {
    const tsResult = gulp.src('src/**/*.ts')
        .pipe(tsProject())

    return tsResult.js.pipe(gulp.dest('lib'))
})

gulp.task("tslint", () =>
    gulp.src("src/**/*.ts")
        .pipe(gulpTslint({
            fix: true,
            formatter: "prose",
            program: tsLint.Linter.createProgram("./tsconfig.json")
        }))
        .pipe(gulpTslint.report({
            emitError: false,
            allowWarnings: true
        }))
)

gulp.task("watch", ["default"], function () {
    gulp.watch('src/**/*.ts', ["ts"])
    gulp.watch('src/**/*.ts', ["tslint"])
})

gulp.task("default", ["ts", "tslint"])
